﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Joyintech.Common;
using Joyintech.Model.inpiao365;
using System.Text;
using Joyintech.BLL.inpiao365;

namespace Joyintech.Web.inpiao365.Users
{
    public partial class showTime : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //kfilmid、kcinemaid
                if (DNTRequest.GetQueryString("kfilmid") != "" && DNTRequest.GetQueryString("kcinemaid") != "")
                {
                    DataBindTheater(DNTRequest.GetQueryString("kfilmid"), DNTRequest.GetQueryString("kcinemaid"));
                }
            }
        }

        /// <summary>
        /// 获取指定城市、指定电影当前上映的影院
        /// </summary>
        /// <param name="movieId">电影编号</param>
        /// <param name="theaterId">影院编号</param>
        private void DataBindTheater(string movieId, string theaterId)
        {
            List<movieOnTheater> list = new List<movieOnTheater>();

            list = new movieOnTheater_BLL().GetModelList("movieId=" + movieId + " and theaterId=" + theaterId);

            StringBuilder strToday = new StringBuilder();
            StringBuilder strTomorrow = new StringBuilder();

            string strTodayHeader = string.Empty;
            string strTomorrowHeader = string.Empty;

            foreach (movieOnTheater model in list)
            {
                if (model.MovieSeatTime.Date == DateTime.Now.Date)
                {
                    strToday.AppendLine("<a class=\"today\" style=\"position: relative;\" target=\"_blank\" href=\"/PhenixTicket/phenix_seat_list_new.aspx?ScreeningsId=" + model.ScreeningsId + "\">" + model.MovieSeatTime.ToString("HH:mm"));
                    strToday.AppendLine("<div id=\"m_popic\" class=\"movie_popic\">");
                    strToday.AppendLine("	<table border=\"0\" style=\"margin: 0 auto;\" cellpadding=\"0\" cellspacing=\"0\">");
                    strToday.AppendLine("		<tr>");
                    strToday.AppendLine("			<td style=\"width: 5px; height: 18px; font-size: 1px; background: url(/images/icon_4.gif);\">");
                    strToday.AppendLine("			</td>");
                    strToday.AppendLine("			<td bgcolor=\"#74A5D6\" height=\"18\">￥ " + model.Price + "</td>");
                    strToday.AppendLine("			<td width=\"5\" style=\"font-size: 1px;\" valign=\"bottom\">");
                    strToday.AppendLine("			<img src=\"/images/icon_5.gif\" /></td>");
                    strToday.AppendLine("		</tr>");
                    strToday.AppendLine("	</table>");
                    strToday.AppendLine("</div>");
                    strToday.AppendLine("</a>");
                }
                else if (model.MovieSeatTime.Date == DateTime.Now.AddDays(1).Date)
                {
                    strTomorrow.AppendLine("<a class=\"today\" style=\"position: relative;\" target=\"_blank\" href=\"/PhenixTicket/phenix_seat_list_new.aspx?ScreeningsId=" + model.ScreeningsId + "\">" + model.MovieSeatTime.ToString("HH:mm"));
                    strTomorrow.AppendLine("<div id=\"m_popic\" class=\"movie_popic\">");
                    strTomorrow.AppendLine("	<table border=\"0\" style=\"margin: 0 auto;\" cellpadding=\"0\" cellspacing=\"0\">");
                    strTomorrow.AppendLine("		<tr>");
                    strTomorrow.AppendLine("			<td style=\"width: 5px; height: 18px; font-size: 1px; background: url(/images/icon_4.gif);\">");
                    strTomorrow.AppendLine("			</td>");
                    strTomorrow.AppendLine("			<td bgcolor=\"#74A5D6\" height=\"18\">￥ " + model.Price + "</td>");
                    strTomorrow.AppendLine("			<td width=\"5\" style=\"font-size: 1px;\" valign=\"bottom\">");
                    strTomorrow.AppendLine("			<img src=\"/images/icon_5.gif\" /></td>");
                    strTomorrow.AppendLine("		</tr>");
                    strTomorrow.AppendLine("	</table>");
                    strTomorrow.AppendLine("</div>");
                    strTomorrow.AppendLine("</a>");
                }
            }

            if (strToday.ToString().Length > 0)
            {
                strTodayHeader = "<li><s>今日<span>（" + DateTime.Today.ToString("yyyy-MM-dd") + "）</span></s>";
                strToday.AppendLine("<div class=\"clr\"></div></li>");
            }

            if (strTomorrow.ToString().Length > 0)
            {
                strTomorrowHeader = "<li><s>明日<span>（" + DateTime.Today.AddDays(1).ToString("yyyy-MM-dd") + "）</span></s>";
                strTomorrow.AppendLine("<div class=\"clr\"></div></li>");
            }

            if (strToday.ToString().Length == 0 && strTomorrow.ToString().Length == 0)
            {
                this.litShowTime.Text = "暂无场次！";
            }
            else
            {
                this.litShowTime.Text = strTodayHeader + strToday.ToString() + strTomorrowHeader + strTomorrow.ToString();
            }
        }
    }
}